#!/usr/bin/python
# -*-coding:UTF-8 -*-

# ========================
# @Time  : 2021/2/1
# @Author: Sunny
# ========================

import unittest
import requests

def decorator01(fun):
    def warpeer(*args,**kwargs):
        for i in range(3):
            try:
                # if i<3:
                print(f'--------------第{i+1}次请求------------')
                fun(*args,**kwargs)
            except (requests.exceptions.ConnectTimeout, requests.exceptions.Timeout) as e:
                print(e)
                print(f'--------------第{i + 1}次请求出现了网络超时，现重新请求------------')
                if i ==2:
                    raise e
            else:
                break

    return warpeer


class TestLogin(unittest.TestCase):


    @decorator01
    def test_login(self):
        url = 'https://www.baidu.com'
        response = requests.get(url,timeout=5)
        assert response.status_code == 200

